import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiSkillPage(Base):
    """
    语音训练技能页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的返回键
        self.skill_back_btn = (By.XPATH, Yomi.RESOURCE_ID.format('ivBack'))

        # 技能列表标题
        self.skill_list_title_text = (By.XPATH, Yomi.RESOURCE_ID.format("tv_action"))

        # 技能图标
        self.skill_ability_icon = (By.XPATH, Yomi.skills_icon.format(""))

        # 技能标题
        self.skill_ability_title_text = (By.XPATH, Yomi.skills_text.format(""))

        # 导航
        self.skill_navigation_icon = (By.XPATH, Page.TEXT.format("导航到"))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.skill_back_btn)

    def click_navigation(self, index="导航到"):
        """
        点击左侧的导航

        :return:None
        """
        self.skill_navigation_icon = (By.XPATH, Page.TEXT.format(index))
        self.click_element(self.skill_navigation_icon)

    def get_list_title(self):
        """
        获取yomi技能列表标题

        :return:获取元素
        """
        return self.find_element_o(self.skill_list_title_text)

    def get_ability_title(self, index=1):
        """
        获取yomi技能名称

        :return:获取元素
        """
        self.skill_ability_title_text = (By.XPATH, Yomi.skills_text.format(index))
        return self.find_element_o(self.skill_ability_title_text)

    def click_ability(self, index=1):
        """
        点击技能图标

        :return:None
        """
        self.skill_ability_icon = (By.XPATH, Yomi.skills_icon.format(index))
        self.click_element(self.skill_ability_icon)

    def click_ability_title(self, index=1):
        """
        点击技能标题

        :return:None
        """
        self.skill_ability_title_text = (By.XPATH, Yomi.skills_text.format(index))
        self.click_element(self.skill_ability_title_text)

    def is_display_yomi_skill(self):
        """
        查看是否进入语音训练技能页

        :return:
        """
        return self.is_display(self.skill_list_title_text)
